//
//  MyShareViewCell.m
//  phmall
//
//  Created by admin on 2017/12/9.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "MyShareViewCell.h"

@implementation MyShareViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    MyShareViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[MyShareViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        self.back=[[UIView alloc]init];
        [self.contentView addSubview:self.back];
        ViewBorderRadius(self.back, 5, 0, [UIColor clearColor]);
        self.back.backgroundColor=[UIColor whiteColor];
        
        self.imgView=[[UIImageView alloc]init];
        [self.back addSubview:self.imgView];
        self.imgView.image=[UIImage imageNamed:@"图片"];
        
        self.title=[[UILabel alloc] init];
        [self.back addSubview:self.title];
        self.title.font=[UIFont systemFontOfSize:15];
        self.title.numberOfLines=2;
        self.title.text=@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度";
        
        self.text=[[UILabel alloc] init];
        [self.back addSubview:self.text];
        self.text.font=[UIFont systemFontOfSize:13];
        self.text.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.text.numberOfLines=3;
        self.text.text=@"获取指定宽度width,字体大小fontSize,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度,字符串value的高度";
        
        self.line=[[UIView alloc]init];
        [self.back addSubview:self.line];
        self.line.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.like=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.like setImage:[UIImage imageNamed:@"喜欢点赞"] forState:UIControlStateNormal];
        [self.like setImage:[UIImage imageNamed:@"喜欢未点"] forState:UIControlStateSelected];
        [self.like setTitle:[NSString stringWithFormat:@"%@%@",@"1000",Localized(@"人喜欢")] forState:UIControlStateNormal];
        self.like.titleLabel.font=[UIFont systemFontOfSize:13];
        [self.like setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.back addSubview:self.like];
        
        self.price=[[UILabel alloc] init];
        [self.back addSubview:self.price];
        self.price.font=[UIFont systemFontOfSize:13];
        self.price.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.price.numberOfLines=0;
        self.price.text=@"₱99999";
        
        self.remove=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.remove setImage:[UIImage imageNamed:@"垃圾桶"] forState:UIControlStateNormal];
        [self.remove setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.remove addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.back addSubview:self.remove];
    }
    return self;
}
-(void)moreAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(removeAction:)]) {
        [self.delegate removeAction:self];
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.right.bottom.offset(-10);
        make.top.offset(0);
    }];
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
        make.bottom.equalTo(self.line.mas_top).offset(-10);
        make.width.mas_equalTo(self.imgView.mas_height);
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.left.equalTo(self.imgView.mas_right).offset(10);
        make.right.offset(-10);
    }];
    
    [self.text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom).offset(10);
        make.left.equalTo(self.imgView.mas_right).offset(10);
        make.right.offset(-10);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(1);
        make.bottom.offset(-30);
    }];
    
    [self.like mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.centerY.equalTo(self.back.mas_bottom).offset(-15);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.equalTo(self.back.mas_bottom).offset(-15);
    }];
    
    [self.remove mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(self.back.mas_bottom).offset(-15);
    }];
}
-(void)setModel:(ShareModel *)model{
    _model=model;
    self.price.text=[NSString stringWithFormat:@"价格:₱%@",model.buy_price];
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMGURL,model.pics[0]]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    NSLog(@"%@",[NSString stringWithFormat:@"%@%@",IMGURL,model.pics[0]]);
//    self.time.text=model.register_date;
    self.text.text=model.comment;
    self.title.text=model.goods_name;
    [self.like setTitle:[NSString stringWithFormat:@"%@ %@",model.love,Localized(@"人喜欢")] forState:UIControlStateNormal];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
